define(["jquery", "easy-admin", "echarts", "echarts-theme", "miniAdmin", "miniTab"], function ($, ea, echarts, undefined, miniAdmin, miniTab) {

    var Controller = {
        index: function () {
            var options = {
                iniUrl: ea.url('ajax/initAdmin'),    // 初始化接口
                clearUrl: ea.url("ajax/clearCache"), // 缓存清理接口
                urlHashLocation: true,      // 是否打开hash定位
                bgColorDefault: false,      // 主题默认配置
                multiModule: true,          // 是否开启多模块
                menuChildOpen: false,       // 是否默认展开菜单
                loadingTime: 0,             // 初始化加载时间
                pageAnim: true,             // iframe窗口动画
                maxTabNum: 20,              // 最大的tab打开数量
            };
            miniAdmin.render(options);

            $('.login-out').on("click", function () {
                ea.request.get({
                    url: 'login/out',
                    prefix: true,
                }, function (res) {
                    ea.msg.success(res.msg, function () {
                        window.location = ea.url('login/index');
                    })
                });
            });
        },
        welcome: function () {

            miniTab.listen();

            /**
             * 报表功能
             */
            var echartsLines = echarts.init(document.getElementById('echarts-lines'), 'walden');
            var optionLines = {
                title: {
                    text: ''
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: []
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    data: ['8月19日', '8月20日', '8月21日', '8月22日', '8月23日', '8月24日', '8月25日']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: [820, 932, 901, 934, 1290, 1330, 1320],
                        type: 'line',
                        smooth: true
                    }
                ]
            };
            /*$.post("/admin/Index/statisticApi",
                function (data) {
                    var list = data.list;
                    optionRecords.legend.data = data.legend;
                    optionRecords.xAxis.data = data.xarr;
                    optionRecords.series = list;
                    echartsRecords.setOption(optionRecords);
                });*/
            echartsLines.setOption(optionLines);
            window.addEventListener("resize", function () {
                echartsLines.resize();
            });

            var echartsRecords = echarts.init(document.getElementById('echarts-records'), 'walden');
            var optionRecords = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                legend: {
                    data: ['投诉', '建议', '待回复投诉', '已回复投诉', '待回复建议', '已回复建议']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        data: ['8月19日', '8月20日', '8月21日', '8月22日', '8月23日', '8月24日', '8月25日']
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '待回复投诉',
                        type: 'bar',
                        stack: '投诉',
                        emphasis: {
                            focus: 'series'
                        },
                        barWidth:40,
                        data: [320, 332, 301, 334, 390, 330, 320]
                    },
                    {
                        name: '已回复投诉',
                        type: 'bar',
                        stack: '投诉',
                        emphasis: {
                            focus: 'series'
                        },
                        barWidth:40,
                        data: [120, 132, 101, 134, 90, 230, 210]
                    },
                    {
                        name: '待回复建议',
                        type: 'bar',
                        stack: '建议',
                        emphasis: {
                            focus: 'series'
                        },
                        barWidth:40,
                        data: [862, 1018, 964, 1026, 1679, 1600, 1570],
                    },
                    {
                        name: '已回复建议',
                        type: 'bar',
                        stack: '建议',
                        emphasis: {
                            focus: 'series'
                        },
                        markLine: {
                            lineStyle: {
                                type: 'dashed'
                            },
                            data: [[{ type: 'min' }, { type: 'max' }]]
                        },
                        barWidth:40,
                        data: [620, 732, 701, 734, 1090, 1130, 1120]
                    },
                ]
            };
            /*$.post("/admin/Index/statisticApi",
                function (data) {
                    var list = data.list;
                    optionRecords.legend.data = data.legend;
                    optionRecords.xAxis.data = data.xarr;
                    optionRecords.series = list;
                    echartsRecords.setOption(optionRecords);
                });*/
            echartsRecords.setOption(optionRecords);
            window.addEventListener("resize", function () {
                echartsRecords.resize();
            });
        },
        editAdmin: function () {
            ea.listen();
        },
        editPassword: function () {
            ea.listen();
        }
    };
    return Controller;
});
